package org.rendao.biz.model;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "searchResult")
@XmlAccessorType(XmlAccessType.NONE)
public class SearchResult<T> {

	@XmlElement
	private int totalCount;
	
	@XmlElementWrapper
	@XmlAnyElement(lax = true)
	private List<T> records;

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public List<T> getRecords() {
		return records;
	}

	public void setRecords(List<T> records) {
		this.records = records;
	}
	
	private SearchResult() {
	}
	
	public static <T> SearchResult <T> byCollection(List<T> list) {
		SearchResult<T> result = new SearchResult<T>();
		result.setRecords(list);
		result.setTotalCount(list.size());
		return result;
	}
}
